package org.example.entity;

import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.hibernate.annotations.CacheConcurrencyStrategy;


@Entity
@Table(name = "group")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class GroupModel extends AbstractModel
{
  private String name;
  private Set<UserModel> members;


  public GroupModel()
  {
    super();
  }


  @Basic(optional = false)
  @Column(nullable = false, name = "name")
  @NotNull
  public String getName()
  {
    return name;
  }


  public void setName(String name)
  {
    this.name = name;
  }


  @ManyToMany
  @JoinTable(name = "user_group",
             joinColumns =
             @JoinColumn(name="user_id", referencedColumnName="id"),
             inverseJoinColumns =
             @JoinColumn(name="group_id", referencedColumnName="id"))
  public Set<UserModel> getMembers()
  {
    return members;
  }


  public void setMembers(Set<UserModel> members)
  {
    this.members = members;
  }

}
